<?php
require "model/register.model.php";

$username = $_POST['username'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$password = $_POST['password'];
$sex = $_POST['sex'];
$regtime = time();

$re = register::ifexit($username);//调用register下面的ifexit()方法,返回受影响的行数,用来判断用户名是否已注册;

if($re -> rowCount()){
	
	echo "<script>alert('用户名已存在了');parent.location.href='./login.php';</script>";
	exit;
}else{
	$rs = register::adduser($username,$phone,$email,$password,$sex,$regtime);	//调用register下面的adduser方法,返回一个受影响的行数,判断是否添加到数据库中   
    if($rs){
    echo "<script>alert('注册成功,跳转到登入页');parent.location.href='./login.php';</script>";
 
   }	
}

